<?php
namespace Common\Model;

/**
 * Person Model Class
 *
 * @package Common\Model
 * @author lythesia
**/
class PersonModel extends BaseModel {
  protected $tableName = 'person';

  protected $_link = array(

    /*
     * Relation Genre
     */
    'Genre' => array(
      'mapping_type'        => self::MANY_TO_MANY,
      'class_name'          => 'Genre',
      'mapping_name'        => 'genres',
      'foreign_key'         => 'person_id',
      'relation_foreign_key'=> 'genre_id',
      'relation_table'      => 'persongenre',
      'mapping_fields'      => 'id,name'
    ),

    /*
     * Relation Movie
     */
    'Movie' => array(
      'mapping_type'        => self::MANY_TO_MANY,
      'class_name'          => 'Movie',
      'mapping_name'        => 'movies',
      'foreign_key'         => 'subject',
      'relation_foreign_key'=> 'object',
      'relation_table'      => 'personmovie',
      'mapping_fields'      => 'id,title,releasedate,rating,ratingnum,genre,poster,group_concat(a.relation) as relation,rtrim(substring_index(summary, ",", 5)) as summary,a.objectimdbid as imdb,a.objectdbpediaid as dbpedia',
      'mapping_order'       => 'b.releasedate desc',
      'condition'           => '1 group by b.id',
    ),

    /*
     * Relation CastMovie
     */
    'CastMovie' => array(
      'mapping_type'        => self::MANY_TO_MANY,
      'class_name'          => 'Movie',
      'mapping_name'        => 'castmovies',
      'foreign_key'         => 'subject',
      'relation_foreign_key'=> 'object',
      'relation_table'      => 'personmovie',
      'mapping_fields'      => 'id,title,releasedate,rating,genre,poster',
      'condition'           => 'relation = "actor"',
    ),

    /*
     * Relation CrewMovie
     */
    'CrewMovie' => array(
      'mapping_type'        => self::MANY_TO_MANY,
      'class_name'          => 'Movie',
      'mapping_name'        => 'crewmovies',
      'foreign_key'         => 'subject',
      'relation_foreign_key'=> 'object',
      'relation_table'      => 'personmovie',
      'mapping_fields'      => 'id,title,releasedate,rating,genre,poster,group_concat(a.relation) as relation',
      'condition'           => 'relation != "actor" group by b.id',
    ),
  );
}
